import { createI18n } from 'vue-i18n'

const zh = {
  errorOccurred: '发生了个错误',
  logoutSuccess: '登出成功',
  useThumbnailPreview: '使用缩略图预览',
  pollingInterval: '轮询间隔',
  smallerIntervalMeansMoreNetworkTraffic: '越小对网络压力越大',
  gridThumbnailWidth: '网格缩略图宽度',
  largeGridThumbnailWidth: '大尺寸网格缩略图宽度',
  pause: '暂停',
  start: '开始',
  waitingUploadCount: '等待上传数量',
  uploadFailureCount: '上传失败数量',
  completedCount: '已完成数量',
  realTimeLog: '实时日志',
  tip: '提示',
  clickToViewLogs:
    '点击下面查看具体日志，若有日志错误内包含名字不合规，可尝试在sd-webui的设置页换一种图像文件名格式，例如[datetime<%Y-%m-%d %H-%M-%S>]',
  startedAt: '开始于：',
  sortByDateAscending: '日期升序',
  sortByDateDescending: '日期降序',
  sortByNameAscending: '名称升序',
  sortByNameDescending: '名称降序',
  sortBySizeAscending: '大小升序',
  sortBySizeDescending: '大小降序',
  inputAddressAndPressEnter: '输入地址回车',
  go: '前往',
  unknownError: '未知错误',
  loadingNextFolder: '即将加载下一个文件夹的文件',
  moveFailedCheckPath: '移动失败，检查你的路径输入',
  detailList: '详情列表',
  previewGrid: '预览网格',
  largePreviewGrid: '大尺寸预览网格',
  sortBy: '按照',
  moveSelectedFilesTo: '下列文件移动至',
  confirm: '确定?',
  upload: '上传',
  download: '下载',
  local: '本地',
  cloud: '云盘',
  confirmCreateTask: '确定创建{type}任务。{more}',
  sendImageFailed: '发送图像失败，请携带console的错误消息找开发者',
  confirmDelete: '确认删除？',
  deleteSuccess: '删除成功',
  dependenciesNotInstalled: '尚未安装依赖，当前不可用',
  login: '登录',
  doubleClickToCopy: '双击复制',
  root: '根',
  drive: '盘',
  refresh: '刷新',
  quickMove: '快速移动',
  more: '更多',
  viewMode: '查看模式',
  sortingMethod: '排序方法',
  copyPath: '复制路径',
  deleteSelected: '删除选中',
  previewInNewWindow: '在新窗口预览（如果浏览器处理不了会下载，大文件的话谨慎）',
  downloadDirectly: '直接下载（大文件的话谨慎）',
  copySourceFilePreviewLink: '复制源文件预览链接',
  viewGenerationInfo: '查看生成信息(prompt等)',
  sendToTxt2img: '发送到文生图',
  sendToImg2img: '发送到图生图',
  sendToInpaint: '发送到局部重绘',
  sendToExtraFeatures: '发送到附加功能',
  loadNextPage: '加载下一页',
  autoUpload: '自动上传',
  localFile: '本地文件',
  baiduCloud: '百度云',
  taskRecord: '任务记录',
  globalSettings: '全局设置',
  onlyOneTaskRecordAllowed: '任务记录有且只能有一个，如果特殊需求请前往仓库提issue',
  welcome: '欢迎',
  openInNewWindow: '在新页面打开',
  restoreLastRecord: '还原上次记录',
  launch: '启动',
  walkMode: '使用 Walk 模式浏览图片',
  launchFromQuickMove: '从快速移动启动',
  recent: '最近',
  emptyStartPage: '空启动页',
  deleteNotAllowedWithOnePaneLeft: '在仅剩一个pane的情况下，不允许删除!!!',
  t2i: '文生图',
  i2i: '图生图',
  saveButtonSavesTo: '使用“保存”按钮保存图像的目录',
  extra: '附加',
  gridImage: '宫格图',
  'i2i-grid': '图生图网格',
  image: '图像',
  't2i-grid': '文生图宫格',
  workingFolder: '工作文件夹',
  lang: '语言',
  langChangeReload: '重新加载: 一些变化可能需要在重新加载后生效',
  hypernetworks: '超网络模型',
  openOnTheRight: '在右边打开',
  openInNewTab: '在新标签打开',
  loginPrompt: '这个功能要求你先使用BDUSS登录到百度云盘。',
  openWithWalkMode: '使用 Walk 模式打开',
  longPressOpenContextMenu: '支持使用长按打开右键菜单',
  baiduNetdiskCollapseTitle: '百度云盘相关功能(仅预览图片无需打开)',
  clickHere2install: '点此安装',
  searchResults: "搜索结果",
  imgSearch: '图像搜索'
}
const en: Record<keyof typeof zh, string> = {
  errorOccurred: 'An error occurred',
  logoutSuccess: 'Logged out successfully',
  useThumbnailPreview: 'Use thumbnail preview',
  pollingInterval: 'Polling interval',
  smallerIntervalMeansMoreNetworkTraffic: 'Smaller interval means more network traffic',
  gridThumbnailWidth: 'Grid thumbnail width',
  largeGridThumbnailWidth: 'Large grid thumbnail width',
  pause: 'Pause',
  start: 'Start',
  waitingUploadCount: 'Waiting upload count',
  uploadFailureCount: 'Upload failure count',
  completedCount: 'Completed count',
  realTimeLog: 'Real-time log',
  tip: 'Tip',
  clickToViewLogs:
    'Click below to view specific logs. If there are naming errors, try changing the image filename format on the sd-webui settings page, such as [datetime<%Y-%m-%d %H-%M-%S>]',
  startedAt: 'Started at: ',
  sortByDateAscending: 'Date ascending',
  sortByDateDescending: 'Date descending',
  sortByNameAscending: 'Name ascending',
  sortByNameDescending: 'Name descending',
  sortBySizeAscending: 'Size ascending',
  sortBySizeDescending: 'Size descending',
  inputAddressAndPressEnter: 'Input address and press Enter',
  go: 'Go',
  unknownError: 'Unknown error',
  loadingNextFolder: 'Loading files from the next folder',
  moveFailedCheckPath: 'Move failed. Check your path input.',
  detailList: 'Detail list',
  previewGrid: 'Preview grid',
  largePreviewGrid: 'Large preview grid',
  sortBy: 'Sort by',
  moveSelectedFilesTo: 'Move selected files to',
  confirm: 'Confirm?',
  upload: 'Upload',
  download: 'Download',
  local: 'Local',
  cloud: 'Cloud',
  confirmCreateTask: 'Confirm to create {type} task. {more}',
  sendImageFailed:
    'Failed to send image. Please contact the developer with the error message from the console.',
  confirmDelete: 'Are you sure you want to delete?',
  deleteSuccess: 'Deleted successfully',
  dependenciesNotInstalled: 'Dependencies not installed. Currently unavailable.',
  login: 'Login',
  doubleClickToCopy: 'Double-click to copy',
  root: 'Root',
  drive: ' drive',
  refresh: 'Refresh',
  quickMove: 'Quick move',
  more: 'More',
  viewMode: 'View mode',
  sortingMethod: 'Sorting method',
  copyPath: 'Copy path',
  deleteSelected: 'Delete selected',
  previewInNewWindow:
    'Open in new window (will download if browser cannot handle it, use with caution for large files)',
  downloadDirectly: 'Download directly (use with caution for large files)',
  copySourceFilePreviewLink: 'Copy source file preview link',
  viewGenerationInfo: 'View generation information (prompt, etc.)',
  sendToTxt2img: 'Send to txt2img',
  sendToImg2img: 'Send to img2img',
  sendToInpaint: 'Send to Inpaint',
  sendToExtraFeatures: 'Send to Extra',
  loadNextPage: 'Load next page',
  autoUpload: 'Auto upload',
  localFile: 'Local file',
  baiduCloud: 'Baidu Netdisk',
  taskRecord: 'Task record',
  globalSettings: 'Global settings',
  onlyOneTaskRecordAllowed:
    'Only one task record is allowed. If you have special requirements, please open an issue on the repository.',
  welcome: 'Welcome',
  openInNewWindow: 'Open in new tab',
  restoreLastRecord: 'Restore last record',
  launch: 'Launch',
  walkMode: 'Use Walk mode to browse images',
  launchFromQuickMove: 'Launch from Quick Move',
  recent: 'Recent',
  emptyStartPage: 'Empty start page',
  deleteNotAllowedWithOnePaneLeft: 'Deletion is not allowed with only one pane left!!!',
  t2i: 'Text to image',
  i2i: 'Image to image',
  saveButtonSavesTo: 'Directory for saving images using the Save button',
  extra: 'Extra',
  gridImage: 'Grid image',
  'i2i-grid': 'Image to image grid',
  image: 'Image',
  't2i-grid': 'Text to image grid',
  workingFolder: 'Working folder',
  lang: 'Language',
  langChangeReload: 'Reload: Some changes may require a reload to take effect',
  hypernetworks: 'hypernetworks',
  openOnTheRight: 'Open on the right',
  openInNewTab: 'Open in a new tab',
  loginPrompt: 'This feature requires you to log in to Baidu Cloud Drive using your BDUSS.',
  openWithWalkMode: 'Open with Walk Mode',
  longPressOpenContextMenu: 'Support long press to open right-click menu',
  baiduNetdiskCollapseTitle:
    "Baidu Netdisk functions (only previewing images don't require opening)",
  clickHere2install: 'Click here to install',
  searchResults: "Search Results",
  imgSearch: 'Image Search'
}
declare module 'vue' {
  export interface ComponentCustomProperties {
    $t (key: keyof typeof zh, ...args: []): string
  }
}

export const getPreferredLang = () => {
  const lang = navigator.language.toLowerCase()
  if (lang.includes('zh') || lang.includes('cn')) {
    return 'zh'
  }
  return 'en'
}

export const i18n = createI18n({
  locale: getPreferredLang(),
  fallbackLocale: 'en',
  messages: {
    zh ,
    en
  },
  legacy: false
})

export const { t, locale } = i18n.global
